import { Http } from "@/utils/request";
import { Toast } from "@/utils/toast";
import { delayTask } from "@/utils/timer";

const baseUrl = "/guider_home";

export const feed_back_types_api = (showError = true) => {
  return Http.get<any[]>(`${baseUrl}/feed_back/types`).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const feed_back_add_api = (data: any, showError = true) => {
  return Http.post(`${baseUrl}/feed_back/add`, data).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const guider_file_list_api = (
  data: { type: number } & MiniApp.PagingQuery,
  showError = true
) => {
  return Http.get<MiniApp.PagingData>(
    `${baseUrl}/guider_file/list`,
    data
  ).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const guider_file_add_api = (
  data: { type: number; file_url: string[] },
  showError = true
) => {
  return Http.post(`${baseUrl}/guider_file/add`, data).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const guider_file_del_api = (data: { id: string }, showError = true) => {
  return Http.post(`${baseUrl}/guider_file/del`, data).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const order_merge_list_api = (
  data: { pay_status: number; order_list_type: number } & MiniApp.PagingQuery,
  showError = true
) => {
  return Http.get<MiniApp.PagingData>(
    `${baseUrl}/order_merge/list`,
    data
  ).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const order_merge_info_api = (
  data: { order_id: string; order_list_type: string },
  showError = true
) => {
  return Http.get<any>(`${baseUrl}/order_merge/info`, data).catch(
    (error: Error) => {
      showError && delayTask(60, () => Toast.show(error.message));
      return Promise.reject(error);
    }
  );
};

export const offline_course_order_mini_pay_api = (
  data: { order_id: string },
  showError = true
) => {
  return Http.post<any>(`${baseUrl}/offline_course_order/mini_pay`, data).catch(
    (error: Error) => {
      showError && delayTask(60, () => Toast.show(error.message));
      return Promise.reject(error);
    }
  );
};

export const live_course_mini_pay_api = (
  data: { order_id: string },
  showError = true
) => {
  return Http.post<any>(`${baseUrl}/live_course/mini_pay`, data).catch(
    (error: Error) => {
      showError && delayTask(60, () => Toast.show(error.message));
      return Promise.reject(error);
    }
  );
};

export const my_like_api = (
  data: { type: number } & MiniApp.PagingQuery,
  showError = true
) => {
  return Http.get<MiniApp.PagingData>(`${baseUrl}/my/like`, data).catch(
    (error: Error) => {
      showError && delayTask(60, () => Toast.show(error.message));
      return Promise.reject(error);
    }
  );
};

export const my_favorite_api = (
  data: { type: number } & MiniApp.PagingQuery,
  showError = true
) => {
  return Http.get<MiniApp.PagingData>(`${baseUrl}/my/favorite`, data).catch(
    (error: Error) => {
      showError && delayTask(60, () => Toast.show(error.message));
      return Promise.reject(error);
    }
  );
};
